<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 13-2-5
 * Time: 下午2:07
 * To change this template use File | Settings | File Templates.
 */
class static_mail
{
    /**
     * 发送邮件
     */
    public static function send($address, $subject, $content, $username = '')
    {
        try {
            require_once(SYS_PATH.'/vendor/PHPMailer_5.2.2/class.phpmailer.php');

            $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
            //$mail->IsSendmail(); // telling the class to use SendMail transport
            $mail->IsSMTP(); // telling the class to use SMTP

            $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
            // 1 = errors and messages
            // 2 = messages only
            $mail->SMTPAuth   = true;                  // enable SMTP authentication
            //$mail->SMTPSecure = "ssl";

            $mail->Host       = "mx2.24money.com"; // sets the SMTP server
            //$mail->Host       = "172.16.11.61"; // sets the SMTP server

            $mail->Port       = 25;                    // set the SMTP port for the GMAIL server
            $mail->Username   = "jrkj_dkpt@24money.com"; // SMTP account username
            $mail->Password   = "jrkj_dkpt";        // SMTP account password
            $mail->CharSet    = "UTF-8";

            $mail->SetFrom('jrkj_dkpt@24money.com', '平安银行网上直销店');
            $mail->Subject = $subject;
            $mail->MsgHTML($content);

            $mail->AddAddress($address, $username == '' ? $address : $username);
            $info = $mail->Send();
            return $info;
        } catch (Exception $e) {
            static_function::write_log("邮件发送失败\t".$e->getMessage());
            return false;
        }
    }
}
